/*!
 Temelia - Skip-list performance tests.

 Copyright (C) 2008 Ceata (http://cod.ceata.org/proiecte/temelia).

 @author Dascalu Laurentiu

 This program is free software; you can redistribute it and
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 3
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "include/performance.hpp"
#include "include/testutil.hpp"

extern "C"
{
#include <temelia/skip_list.h>
}

static void temelia_skip_list_search(int n)
{
	skip_list_t skip_list;

	skip_list = skip_list_new(32);

	for (int i = 0; i < n; i++)
		skip_list_insert(skip_list, default_collection[i], int_compare, NULL);

	for (int i = 0; i < n; i++)
		skip_list_search(skip_list, default_collection[i], int_compare, NULL);

	skip_list_delete(skip_list);
}

static void temelia_skip_list_insert(int n)
{
	skip_list_t skip_list;

	skip_list = skip_list_new(32);

	for (int i = 0; i < n; i++)
		skip_list_insert(skip_list, default_collection[i], int_compare, NULL);
	skip_list_delete(skip_list);
}

static void temelia_skip_list_remove(int n)
{
	skip_list_t skip_list;

	skip_list = skip_list_new(32);

	for (int i = 0; i < n; i++)
		skip_list_insert(skip_list, default_collection[i], int_compare, NULL);

	for (int i = 0; i < n; i++)
		skip_list_remove(skip_list, default_collection[i], int_compare, NULL);

	skip_list_delete(skip_list);
}

void TemeliaPerformance::pt_skip_list(void)
{
	TestUnit testUnit("skip_list");

	GENERATE_TEMELIA_TEST(testUnit, "insert", skip_list_insert);
	GENERATE_TEMELIA_TEST(testUnit, "search", skip_list_search);
	GENERATE_TEMELIA_TEST(testUnit, "remove", skip_list_remove);

	testUnit.write(fout);
}
